﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using NewRetail.Application.Components.Advertisement;
using NewRetail.Application.Components.Advertisement.Entity;
using NewRetail.Application.Components.Goods;
using NewRetail.Application.Components.Goods.Entity;
using NewRetail.Application.Components.Platform;
using NewRetail.Application.Components.Platform.Entity;
using NewRetail.Application.Components.PrintTask;
using NewRetail.Application.Components.PrintTask.Entity;
using NewRetail.Application.Components.StoreValueCard.Entity;
using NewRetail.Application.Components.TianQue;
using NewRetail.Application.Components.TianQue.Entity;
using NewRetail.Application.Components.Warehouse;
using NewRetail.Application.Components.Warehouse.Entity;
using NewRetail.Application.Components.WeChat.CardVoucher;
using NewRetail.Application.Components.WeChat.CardVoucher.Entity;
using NewRetail.Application.Components.WechatOrAlipayPayment;
using NewRetail.Application.Components.WechatOrAlipayPayment.Entity;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;

namespace NewRetail.Application.DataAccess
{
    [ConnectionStringName("new_retail")]
    public class NewRetailDbContext : AbpDbContext<NewRetailDbContext>
    {
        private readonly ILoggerFactory loggerFactory;
        public NewRetailDbContext(DbContextOptions<NewRetailDbContext> option, ILoggerFactory loggerFactory) : base(option)
        {
            this.loggerFactory = loggerFactory;
        }

        public DbSet<PromoteSalesDiscount> PromoteSalesDiscount { get; set; }
        public DbSet<PromoteSalesDiscountCategory> PromoteSalesDiscountCategory { get; set; }
        public DbSet<PromoteSalesDiscountGoods> PromoteSalesDiscountGoods { get; set; }

        public DbSet<SequenceEntity> SequenceEntity { get; set; }

        public DbSet<GoodsCategory> GoodsCategory { get; set; }
        public DbSet<GoodsInfo> GoodsInfo { get; set; }
        public DbSet<GoodsAdjustPrice> GoodsAdjustPrice { get; set; }

        public DbSet<Warehouse> Warehouse { get; set; }
        public DbSet<WarehouseGoods> WarehouseGoods { get; set; }
        public DbSet<InOutWarehousing> InOutWarehousing { get; set; }
        public DbSet<ChangeWarehouse> changeWarehouses { get; set; }
        public DbSet<CheckStock> checkStocks { get; set; }
        public DbSet<PromoteSalesFullCut> promoteSalesFullCuts { get; set; }
        //add by cl 20240311
        public DbSet<PromoteSalesFullCutCategory> PromoteSalesFullCutCategory { get; set; }//满减关联分类
        public DbSet<WholesaleCustomer> warehouseConsumers { get; set; }
        public DbSet<WholesaleInOut> warehouseInOuts { get; set; }
        public DbSet<WholesaleReceipt> warehouseReceipts { get; set; }

        public DbSet<PaymentReceipt> paymentReceipts { get; set; }
        public DbSet<PosDiscount> PosDiscount { get; set; }
        public DbSet<PosCashier> posCashiers { get; set; }
        public DbSet<PosCashRegister> posCashRegisters { get; set; }
        public DbSet<PosIntegral> posIntegrals { get; set; }
        public DbSet<PosIntegralRule> posIntegralRules { get; set; }
        public DbSet<PosMember> posMembers { get; set; }
        public DbSet<PosMemberType> posMemberTypes { get; set; }
        public DbSet<PosDaySum> posPayDaySums { get; set; }
        public DbSet<PosPayFlow> posPayFlows { get; set; }
        public DbSet<PosSalesFlow> posSalesFlows { get; set; }
        public DbSet<Supplier> suppliers { get; set; }
        public DbSet<CardVoucherInfo> cardVoucherInfos { get; set; }
        public DbSet<UserCouponsInfo> userCouponsInfos { get; set; }

        #region add by cl
        /// <summary>
        /// 其他单
        /// </summary>
        public DbSet<OtherBill> otherBills { get; set; }
        /// <summary>
        /// 积分兑换券设置表
        /// </summary>
        public DbSet<CardVoucherIntegralInfo> cardVoucherIntegralInfos { get; set; }
        /// <summary>
        /// 充值记录表
        /// </summary>
        public DbSet<CardRechargeRecordEntity> cardRechargeRecords { get; set; }
        /// <summary>
        /// 充值方案表
        /// </summary>
        public DbSet<CardRechargeSchemeEntity> cardRechargeSchemes { get; set; }
        /// <summary>
        /// 储值卡余额变化记录表
        /// </summary>
        public DbSet<CardBalanceChangeEntity> CardBalanceChanges { get; set; }
        /// <summary>
        /// 打印任务表
        /// </summary>
        public DbSet<PrintTaskEntity> PrintTasks { get; set; }
        /// <summary>
        /// pos端副屏广告表
        /// </summary>
        public DbSet<AdvertisementInfo> AdvertisementInfos { get; set; }
        /// <summary>
        /// 次品单
        /// </summary>
        public DbSet<DefectiveBill> DefectiveBills { get; set; }
        /// <summary>
        /// 微信/支付宝支付返回结果
        /// </summary>
        public DbSet<PosPayResultFlow> PosPayResultFlows { get; set; }
        #endregion

        /// <summary>
        /// 打印授权码任务表
        /// </summary>
        public DbSet<PrintAuthorizationCodeTaskEntity> PrintAuthorizationCodeTasks { get; set; }

        //add by cl 20230320
        /// <summary>
        /// 商品退货周期
        /// </summary>
        public DbSet<GoodsCategoryReturnCycle> GoodsCategoryReturnCycles { get; set; }

        //add by cl 20240115
        /// <summary>
        /// 天阙支付记录表
        /// </summary>
        public DbSet<TianQuePayRecordEntity> TianQuePayRecord { get; set; }

        //add by cl 20240517
        /// <summary>
        /// 会员价表
        /// </summary>
        public DbSet<GoodsMemberPrice> GoodsMemberPrices { get; set; }

        /// <summary>
        /// 字典表
        /// </summary>
        public DbSet<SysDicsEntity> SysDics { get; set; }
        /// <summary>
        /// 付款方式表
        /// </summary>
        public DbSet<PosPaymentType> PosPaymentTypes { get; set; }
        /// <summary>
        /// 会员促销规则表
        /// </summary>
        public DbSet<PosMemberPromotionRule> PosMemberPromotionRules { get; set; }
        /// <summary>
        /// 积分抵现/兑换规则表
        /// </summary>
        public DbSet<PosIntegralUsageRule> PosIntegralUsageRules { get; set; }
        /// <summary>
        /// 尾数取值规则表
        /// </summary>
        public DbSet<RateRule> RateRules { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.ConfigureGoodsEntities();
            modelBuilder.ConfigureWarehouseEntities();
            modelBuilder.ConfigurePlatformEntities();

            #region add by cl
            modelBuilder.ConfigureCardVoucherEntities();
            modelBuilder.ConfigureUserCouponsEntities();
            modelBuilder.ConfigureCardVoucherIntegralEntities();
            modelBuilder.ConfigureCardRechargeRecordEntities();
            modelBuilder.ConfigureCardRechargeSchemeEntities();
            modelBuilder.ConfigureCardBalanceChangesEntities();
            modelBuilder.ConfigurePrintTaskEntities();
            modelBuilder.ConfigureAdvertEntities();
            modelBuilder.ConfigureWechatOrAlipayPaymentEntities();
            modelBuilder.ConfigurePrintAuthorizationCodeTaskEntities();
            modelBuilder.ConfigureTianQueEntities();
            #endregion
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (this.loggerFactory != null)
            {
                optionsBuilder.UseLoggerFactory(this.loggerFactory);
            }
        }
    }
}
